package com.ruoyi.order.domain;

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.ArrayList;
import java.util.List;

/**
 * 记录表单数据对象 wx_form_record
 * 
 * @author ruoyi
 * @date 2024-09-04
 */
public class WxFormRecord extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /**  */
    private Long id;

    /** 订单编号 */
    @Excel(name = "订单编号")
    private String orderNum;

    /** 订单类型，用于区分该订单员工提交的的表单类型 */
    @Excel(name = "订单类型，用于区分该订单员工提交的的表单类型")
    private Long orderType;

    /** 关联员工表id */
    @Excel(name = "关联员工表id")
    private Long uid;

    /** 关联生成的表单id */
    @Excel(name = "关联生成的表单id")
    private Long formId;

    /** 表单名称，主要用于区分用途（例子：订单wx_32137123712提成表单） */
    @Excel(name = "表单名称，主要用于区分用途", readConverterExp = "例=子：订单wx_32137123712提成表单")
    private String formName;

    /** 用户填写完单后存储的项目数据值信息 */
    private List<WxFormRecordItem> wxFormRecordItemList;

    public void setId(Long id) 
    {
        this.id = id;
    }

    public Long getId() 
    {
        return id;
    }
    public void setOrderNum(String orderNum) 
    {
        this.orderNum = orderNum;
    }

    public String getOrderNum() 
    {
        return orderNum;
    }
    public void setOrderType(Long orderType) 
    {
        this.orderType = orderType;
    }

    public Long getOrderType() 
    {
        return orderType;
    }
    public void setUid(Long uid) 
    {
        this.uid = uid;
    }

    public Long getUid() 
    {
        return uid;
    }
    public void setFormId(Long formId) 
    {
        this.formId = formId;
    }

    public Long getFormId() 
    {
        return formId;
    }
    public void setFormName(String formName) 
    {
        this.formName = formName;
    }

    public String getFormName() 
    {
        return formName;
    }

    public List<WxFormRecordItem> getWxFormRecordItemList()
    {
        return wxFormRecordItemList;
    }

    public void setWxFormRecordItemList(List<WxFormRecordItem> wxFormRecordItemList)
    {
        this.wxFormRecordItemList = wxFormRecordItemList;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("orderNum", getOrderNum())
            .append("orderType", getOrderType())
            .append("uid", getUid())
            .append("formId", getFormId())
            .append("formName", getFormName())
            .append("createTime", getCreateTime())
            .append("createBy", getCreateBy())
            .append("wxFormRecordItemList", getWxFormRecordItemList())
            .toString();
    }

    public static WxFormRecord getWxFormRecord(WxVhiceodr wxVhiceodr, WxForm wxForm) {
        // 获取子项数据
        List<WxFormRecordItem> wxFormRecordItemList = getWxFormRecordItems(wxForm);
        WxFormRecord wxFormRecord = new WxFormRecord();
        wxFormRecord.setWxFormRecordItemList(wxFormRecordItemList);
        wxFormRecord.setFormName(wxForm.getFormName());
        wxFormRecord.setOrderNum(wxVhiceodr.getOrderNum());
        wxFormRecord.setOrderType(wxForm.getOrderType());
        wxFormRecord.setFormId(wxForm.getId());
        return wxFormRecord;
    }

    private static List<WxFormRecordItem> getWxFormRecordItems(WxForm wxForm) {
        List<WxFormItem> wxFormItemList = wxForm.getWxFormItemList();
        List<WxFormRecordItem> wxFormRecordItemList=new ArrayList<>();
        for (WxFormItem wxFormItem : wxFormItemList
        ){
            WxFormRecordItem  wxFormRecordItem=new WxFormRecordItem();
            wxFormRecordItem.setLabel(wxFormItem.getItemLabel());
            wxFormRecordItem.setHandleFlag(wxFormItem.getHandleFlag());
            wxFormRecordItem.setType(wxFormItem.getItemType());
            wxFormRecordItemList.add(wxFormRecordItem);
        }
        return wxFormRecordItemList;
    }
}
